# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Arch Haskell Team <arch-haskell@haskell.org>

_hkgname=servant-server
pkgname=haskell-servant-server
pkgver=0.19.2
pkgrel=49
pkgdesc="A family of combinators for defining webservices APIs and serving them"
url="https://haskell-servant.readthedocs.org/"
license=("BSD")
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-base-compat' 'haskell-aeson' 'haskell-base64-bytestring'
         'haskell-constraints' 'haskell-http-api-data' 'haskell-http-media' 'haskell-http-types'
         'haskell-network-uri' 'haskell-monad-control' 'haskell-network' 'haskell-servant'
         'haskell-sop-core' 'haskell-string-conversions' 'haskell-resourcet' 'haskell-tagged'
         'haskell-transformers-base' 'haskell-wai' 'haskell-wai-app-static' 'haskell-warp'
         'haskell-word8')
makedepends=('ghc' 'uusi' 'haskell-hspec' 'haskell-hspec-wai' 'haskell-should-not-typecheck'
             'haskell-quickcheck' 'haskell-safe' 'haskell-wai-extra' 'haskell-temporary'
             'haskell-transformers-compat')
source=("https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz")
sha512sums=('c0814819ab5c1a4b81204d0a7f9d4f0f4f2ab055066f47ef1c4b803baac45b1c4acf99448055de40f0547caa64a79cc93e80d878c1e61ce792019afb8c6d543b')

prepare() {
    cd $_hkgname-$pkgver
    uusi -u hspec -u hspec-discover -u http-api-data $_hkgname.cabal
}

build() {
    cd $_hkgname-$pkgver

    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $_hkgname-$pkgver
    runhaskell Setup test --show-details=direct
}

package() {
    cd $_hkgname-$pkgver

    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
